package com.lxmes.web.api;

import com.alibaba.fastjson2.JSONObject;
import com.lxmes.base.domain.JcIteminfo;
import com.lxmes.base.service.IJcIteminfoClassService;
import com.lxmes.base.service.IJcIteminfoService;
import com.lxmes.base.service.IJcWarehouseinfoKuweiService;
import com.lxmes.base.service.IJcWarehouseinfoService;
import com.lxmes.business.domain.CcChukuInfo;
import com.lxmes.business.domain.CcRukuInfo;
import com.lxmes.business.mapper.CcChukuInfoMapper;
import com.lxmes.business.mapper.CcRukuInfoMapper;
import com.lxmes.business.service.ICcChukuInfoService;
import com.lxmes.business.service.ICcRukuInfoService;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.system.domain.MhColumnNavigation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.List;

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/dpBb/api")
public class DpBbApi extends BaseController  {
    @Autowired
    private ICcChukuInfoService ccChukuInfoService;
    @Autowired
    private ICcRukuInfoService ccRukuInfoService;
    @Autowired
    private IJcIteminfoService iteminfoService;
    @Autowired
    private IJcIteminfoClassService iJcIteminfoClassService;
    @Autowired
    private IJcWarehouseinfoService warehouseinfoService;
    @Autowired
    private IJcWarehouseinfoKuweiService kuweiService;
    //获取入库数据
    @GetMapping("/getRukuData")
    public AjaxResult getRukuData()
    {
        CcRukuInfo rukuInfo=new CcRukuInfo();
        LocalDate today = LocalDate.now();
        LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
        LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
        rukuInfo.setRukuDateStart(startOfWeek.toString());
        rukuInfo.setRukuDateEnd(endOfWeek.toString());
        List<CcRukuInfo> list = ccRukuInfoService.selectCcRukuInfoDaBbList(rukuInfo);
        return AjaxResult.success(list);
    }
    //获取出库
    @GetMapping("/getChukuData")
    public AjaxResult getChukuData()
    {
        CcChukuInfo chukuInfo=new CcChukuInfo();
        LocalDate today = LocalDate.now();
        LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
        LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
        chukuInfo.setChukuDateStart(startOfWeek.toString());
        chukuInfo.setChukuDateEnd(endOfWeek.toString());
        List<CcChukuInfo> list = ccChukuInfoService.selectCcChukuInfoDaBbList(chukuInfo);
        return AjaxResult.success(list);
    }
    //获取出库
    @GetMapping("/getDpBb1")
    public AjaxResult getDpBb1()
    {
        JSONObject jsonObject =new JSONObject();
        //物料种类
        jsonObject.put("wlQty",iteminfoService.selectJcIteminfoDpBb1());
        //物料分类
        jsonObject.put("wlflQty",iJcIteminfoClassService.selectJcIteminfoClassDpBb1());
        //仓库数量
        jsonObject.put("ckQty",warehouseinfoService.selectJcWarehouseinfoDpBb());
        //车辆数量
        jsonObject.put("clQty",kuweiService.selectJcWarehouseinfoKuweiDpBb("2"));
        return AjaxResult.success(jsonObject);
    }
}
